import {
    Component, ComponentFactoryResolver, ElementRef, ViewContainerRef, Renderer2, OnInit
} from '@angular/core';
import { DrawService } from '../../../../common/draw/draw.service';
import { PsMachineDetailComponent } from '../../../../detail/psMachine/psMachine.detail.component';
import { EsCommonService } from '../../../../common/escommon.service';
import { WarnningService } from '../../../../common/Warnning.service';

@Component({
    templateUrl: './warnning.processed.component.html',
    styleUrls: ['./warnning.processed.component.css', '../../../../app.component.css','../warnning.component.css'],
})
export class WarnningProcessedComponent implements OnInit {
    show: any;
    nowPage: number;
    totalCount: number;
    pageSize;
    basic;
    headers = [
        {
            field: 'startTime',
            title: '开始时间',
            canSort: true,
            width: '15%',
        },
        {
            field: 'endTime',
            title: '最后发生时间',
            canSort: true,
            width: '15%',
        },
        {
            field: 'warn',
            title: '发生次数',
            canSort: true,
            width: '5%',
        },
        {
            field: 'name',
            title: '告警设备',
            canSort: false,
            width: '15%',
        },
        {
            field: 'level',
            title: '告警级别',
            canSort: true,
            width: '5%',
        },
        {
            field: 'reason',
            title: '故障原因',
            canSort: false,
            width: '25%',
        },
        {
            field: 'assignTo',
            title: '处理人',
            canSort: false,
            width: '10%',
        },
        {
            field: 'releation',
            title: '关联业务',
            canSort: false,
            width: '10%',
        }
    ];
    datas: Array<any>;
    constructor(private drawService: DrawService, private elementref: ElementRef, private renderer: Renderer2, private esCommonService: EsCommonService,
        private viewContainerRef: ViewContainerRef, private resolver: ComponentFactoryResolver, private warnningService: WarnningService) {
        this.basic = false;
        this.pageSize = 12;
        this.show = 'today';
    }

    ngOnInit(): void {
        this.loadData({
            pageNo: 1,
            pageSize: this.pageSize,
        });
    }

    loadData(data?) {
        let d = this.warnningService.queryProcessedWarnning(data, this.show);
        this.datas = d.data;
        this.totalCount = d.totalCount;
        //this.totalCount = 100;
        this.nowPage = 1;
    }

    search(event) {
        if (event == null) {
            this.loadData({
                searchTime: this.show,
                pageNo: 1,
                pageSize: this.pageSize,
            });
        } else {
            if (event.key == 'Enter') {
                this.loadData({
                    searchTime: this.show,
                    pageNo: 1,
                    pageSize: this.pageSize,
                });
            }
        }
    }

    paginationChange() {
        this.loadData({
            searchTime: this.show,
            pageNo: this.nowPage,
            pageSize: this.pageSize,
        });
    }

    getStatus(status) {
        return this.esCommonService.getStatus(status);
    }

    getDate(date) {
        if (date == null) {
            return '-';
        }
        let dateObject = new Date(date);

        return this.esCommonService.getFormatDate(dateObject, "yyyy-MM-dd hh:mm:ss")
    }

    sortEvent(event) {
        this.loadData({
            searchTime: this.show,
            pageNo: 1,
            pageSize: this.pageSize,
            sort: event
        });
    }

    openSlider(psMachine) {
        this.drawService.open({
            component: PsMachineDetailComponent,
            data: psMachine
        });
    }

    getLevel(level) {
        switch (level) {
            case 'low':
                return '低';
            case 'mid':
                return '中';
            case 'high':
                return '高';
        }
    }

    downloadPdf() {
        this.esCommonService.downloadPdf("pdf");
    }

    jumpToWarn(machine) {
        debugger;
    }

    changeShow(s) {
        this.show = s;
        this.loadData({
            pageNo: this.nowPage,
            pageSize: this.pageSize,
        });
    }
}